# -*- coding: utf-8 -*-
# @Time : 2021/2/2 9:38
# @Author : 加钱哥
# @Email : scg@gmail.com
# @File : mission_page.py
# @Project : xiangmu

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
class MissionPage():
    def __init__(self,driver):
        self.driver=driver
        self.theme_locator = (By.ID, "subject")
        self.duty_locator = (By.ID, "owner_name")
        self.choose_locator = (By.CSS_SELECTOR, "#ta1 > input")
        self.true_locator = (By.CSS_SELECTOR,"body > div:nth-child(12) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)")
        self.content_locator = (By.CSS_SELECTOR, "#about_roles_name")
        self.choose1_locator = (By.CSS_SELECTOR, "#ta1 > input")
        self.true1_locator = (By.CSS_SELECTOR,"body > div:nth-child(13) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span")
        self.save_locator = (By.NAME, "submit")
        self.desprition_locator = (By.CLASS_NAME, "ke-content")
        self.time_locator = (By.ID, "due_date")
        self.ltbody_locator = (By.CSS_SELECTOR, "#form1 > table > tbody")
        self.tr_locator = (By.TAG_NAME, "tr")
        self.td_locator = (By.TAG_NAME, "td")
        self.input_locator = (By.NAME, "task_id[]")
        self.delect_locator = (By.ID, "delete")
        self.close_locator = (By.TAG_NAME, "a")
        self.save_new_locator=(By.CSS_SELECTOR,"body > div.container > div.row-fluid > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(2)")
        self.return_locatror=(By.CSS_SELECTOR,"body > div.container > div.row-fluid > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(3)")
        self.email_locatror=(By.XPATH,"/html/body/div[5]/div[2]/div/form/table/tbody/tr[2]/td[4]/input[2]")

    def theme(self,theme):
        self.driver.find_element(*self.theme_locator).send_keys(theme)
        self.driver.find_element(*self.duty_locator).click()
    def choose(self):
        self.driver.find_element(*self.choose_locator).click()
        self.driver.find_element(*self.true_locator).click()
    def content(self):
        self.driver.find_element(*self.content_locator).click()
    def choose1(self):
        self.driver.find_element(*self.choose1_locator).click()
        self.driver.find_element(*self.true1_locator).click()
    def select1(self):
        Locator = self.driver.find_element_by_id("select1")
        select = Select(Locator)
        select.select_by_index(1)
    def email(self):
        self.driver.find_element(*self.email_locatror).click()
    def status(self):
        Locator1 = self.driver.find_element_by_name("status")
        selecta = Select(Locator1)
        selecta.select_by_index(2)
    def miaosu(self,desprition):
        self.driver.switch_to.frame(self.driver.find_element_by_class_name("ke-edit-iframe"))
        self.driver.find_element(*self.desprition_locator).send_keys(desprition)
        self.driver.switch_to.parent_frame()
    def end_time(self,time):
        self.driver.find_element(*self.time_locator).send_keys(time)
    def rank(self):
        rank_locator = self.driver.find_element_by_name("priority")
        selectb = Select(rank_locator)
        selectb.select_by_index(1)
    def save(self):
        self.driver.find_element(*self.save_locator).click()
    def get_text(self):
        tbody = self.driver.find_element(*self.ltbody_locator)
        trs = tbody.find_elements(*self.tr_locator)
        for tr in trs:
            tds = tr.find_elements(*self.td_locator)
            return tds[2].text

    def delete(self,content):
        tbody = self.driver.find_element(*self.ltbody_locator)
        trs = tbody.find_elements(*self.tr_locator)
        for tr in trs:
            tds = tr.find_elements(*self.td_locator)
            if tds[2].text == content:
                tds[0].find_element(*self.input_locator).click()
        sleep(2)

    def true(self):
        self.driver.find_element(*self.delect_locator).click()
    def save_new(self):
        self.driver.find_element(*self.save_new_locator).click()
    def current_url(self):
        return self.driver.current_url
    def return_add_mission(self):
        self.driver.find_element(*self.return_locatror).click()
    def accept(self):
        self.driver.switch_to.alert.accept()
        sleep(3)

    def assert_content(self):
        return self.driver.switch_to.alert.text







